package com.wp.common;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {

	//将页面不重复的请求参数转换为Map类型
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Map getParams(HttpServletRequest req){
		Map params = new HashMap();
		Enumeration<String> strs = req.getParameterNames();
		String str;
		while( strs.hasMoreElements()){
			str = strs.nextElement();
			if(req.getParameterValues(str)!=null && !"".equals(req.getParameterValues(str))){
				params.put(str, req.getParameterValues(str)[0]);
			}
		}
		if(null==params.get(CommonConstant.USER_ID) && null != req.getSession().getAttribute(CommonConstant.USER_ID)){
			params.put(CommonConstant.USER_ID,(String)req.getSession().getAttribute(CommonConstant.USER_ID));
		}
		return params;
	}
}
